package com.cykj.web.controller.posbiz;

import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.core.page.TableDataInfo;
import com.cykj.common.enums.BusinessType;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.pos.domain.BizRateData;
import com.cykj.pos.service.IBizRateDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 刷卡扫码费率Controller
 * 
 * @author ruoyi
 * @date 2021-09-02
 */
@RestController
@RequestMapping("/system/data")
public class BizRateDataController extends BaseController
{
    @Autowired
    private IBizRateDataService bizRateDataService;

    /**
     * 查询刷卡扫码费率列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizRateData bizRateData)
    {
        startPage();
        List<BizRateData> list = bizRateDataService.selectBizRateDataList(bizRateData);
        return getDataTable(list);
    }
    @GetMapping(value = "/typePayment/{accountId}")
    public AjaxResult selectBizRateDataskm(@PathVariable String accountId)
    {
        List<BizRateData> bizRatelist= bizRateDataService.selectBizRateDataskm(accountId);
        return AjaxResult.success(bizRatelist);
    }

    /**
     * 导出刷卡扫码费率列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:export')")
    @Log(title = "刷卡扫码费率", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizRateData bizRateData)
    {
        List<BizRateData> list = bizRateDataService.selectBizRateDataList(bizRateData);
        ExcelUtil<BizRateData> util = new ExcelUtil<BizRateData>(BizRateData.class);
        return util.exportExcel(list, "data");
    }

    /**
     * 获取刷卡扫码费率详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bizRateDataService.selectBizRateDataById(id));
    }

    /**
     * 新增刷卡扫码费率
     */
    @PreAuthorize("@ss.hasPermi('system:data:add')")
    @Log(title = "刷卡扫码费率", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizRateData bizRateData)
    {
        return toAjax(bizRateDataService.insertBizRateData(bizRateData));
    }

    /**
     * 修改刷卡扫码费率
     */
    @PreAuthorize("@ss.hasPermi('system:data:edit')")
    @Log(title = "刷卡扫码费率", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizRateData bizRateData)
    {
        return toAjax(bizRateDataService.updateBizRateData(bizRateData));
    }

    /**
     * 删除刷卡扫码费率
     */
    @PreAuthorize("@ss.hasPermi('system:data:remove')")
    @Log(title = "刷卡扫码费率", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizRateDataService.deleteBizRateDataByIds(ids));
    }

}
